S0="${BASH_SOURCE[0]}"
DIRNAME="$( dirname "$S0")"
DIR="$(cd "$DIRNAME" && pwd)"

echo DIR=$DIR
CREATORPROJ=$(realpath $DIR/../CreatorProj)

cp -r $CREATORPROJ/build/android/data $CREATORPROJ/build/android/data_ori

BUILD_NUMBER=${BUILD_NUMBER:-1}
REMOTE_URL_ROOT=${REMOTE_URL_ROOT:-http://192.168.1.113:8080/Game000}
OS=$1
PLATFORM_ID=$2

node bundle_version_generator.js -p ${PLATFORM_ID} -v $(node getVersion.js ab_subgame001).${BUILD_NUMBER} -b ab_subgame001 -u ${REMOTE_URL_ROOT}/hotupdate/${OS}/p${PLATFORM_ID}/subgame-remote-assets/ -s ../CreatorProj/build/android/data/ -t ./subgame-remote-assets/ -d ../CreatorProj/assets/
node bundle_version_generator.js -p ${PLATFORM_ID} -v $(node getVersion.js ab_lobby).${BUILD_NUMBER} -u ${REMOTE_URL_ROOT}/hotupdate/${OS}/p${PLATFORM_ID}/remote-assets/ -s ../CreatorProj/build/android/data/ -t ./remote-assets/ -d ../CreatorProj/assets/
#在最后一次调用bundle_version_generator时,没有bundle参数,则会把注入代码加入到main.js中

if [[ "$HOT_LOCAL_PUBLISH" == "true" ]]; then
    echo "发布到本地nginx"
    LOCAL_URL_ROOT=/opt/homebrew/var/www/Game000/hotupdate/${OS}/p${PLATFORM_ID}
    rsync -avz --delete $DIR/remote-assets/ ${LOCAL_URL_ROOT}/remote-assets/;
    rsync -avz --delete $DIR/subgame-remote-assets/ ${LOCAL_URL_ROOT}/subgame-remote-assets/;
fi